import os


import jieba  # 分词
from matplotlib import pyplot as plt  # 绘图
from wordcloud import WordCloud  # 词云
from PIL import Image  # 图片处理
import numpy as np  # 矩阵运算

from sqlhelper import select


def saveimg():
    if os.path.exists('static\img\ciyun.jpg'):
        os.remove('static\img\ciyun.jpg')
    data = select('SELECT jobName FROM zhaopin ')
    text = ''
    for i in data:
        text = text + i[0]

    cut = jieba.cut(text)
    string = ' '.join(cut)

    img = Image.open(r"static\img\1.jpg")
    img_array = np.array(img)
    wc = WordCloud(
        background_color='#f7f7f7',
        mask=img_array,
        font_path='STCAIYUN.TTF'
    )
    wc.generate_from_text(string)

    fig = plt.figure(1)
    plt.imshow(wc)
    plt.axis('off')

    plt.savefig(r'static\img\ciyun.jpg', dip=1024)


if __name__ == '__main__':
    saveimg()
